package com.aimls.usbkey;

import java.io.FileInputStream;
import java.security.Provider;
import java.security.Security;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Map;


/**
 * 获取USB Key的信息
 * <p>
 * -----------------------------------------------------------------------------
 * <p>
 * 工程名：FusionChartDemo
 * 授权：(C) Copyright TopWalk Corporation 2011
 * <p>
 * 公司 : 北京天行网安信息技术有限责任公司
 * <p>
 * -----------------------------------------------------------------------------
 * <p>
 * <font color="#FF0000">注意: 本内容仅限于北京天行网安公司内部使用，禁止转发</font>
 * <p>
 * 
 * @version 1.0
 * @author 张华永
 * @createDate 2011-12-12
 * @lastModify 2011-12-12
 * @since JDK1.6
 */
public class USBKeyInfo {
	static String issue,after,before,subject;
	static String serialno,signalg;
	static int version;
	
	public void init() throws Exception{
		CertificateFactory certFactory = CertificateFactory.getInstance("X.509");
		
		FileInputStream fi = new FileInputStream("D://zhyKEY/zhy.cer");
		X509Certificate cert = (X509Certificate)certFactory.generateCertificate(fi);
		fi.close();
		
		issue = cert.getIssuerDN().toString();
		after = cert.getNotAfter().toString();
		before = cert.getNotBefore().toString();
		subject = cert.getSubjectDN().toString();
		serialno = cert.getSerialNumber().toString();
		signalg = cert.getSigAlgName();
		version = cert.getVersion();		
	}

	public String getIssue() {
		return issue;
	}

	public void setIssue(String issue) {
		USBKeyInfo.issue = issue;
	}

	public String getAfter() {
		return after;
	}

	public void setAfter(String after) {
		USBKeyInfo.after = after;
	}

	public String getBefore() {
		return before;
	}

	public void setBefore(String before) {
		USBKeyInfo.before = before;
	}

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		USBKeyInfo.subject = subject;
	}

	public String getSerialno() {
		return serialno;
	}

	public void setSerialno(String serialno) {
		USBKeyInfo.serialno = serialno;
	}

	public String getSignalg() {
		return signalg;
	}

	public void setSignalg(String signalg) {
		USBKeyInfo.signalg = signalg;
	}

	public int getVersion() {
		return version;
	}

	public void setVersion(int version) {
		USBKeyInfo.version = version;
	}
	
	public static void main(String[] args) throws Exception {
		USBKeyInfo usbinfo = new USBKeyInfo();
		
		usbinfo.init();
		
		System.out.println(usbinfo.getIssue());
		System.out.println(usbinfo.getAfter());
		System.out.println(usbinfo.getBefore());
		System.out.println(usbinfo.getSubject());
		System.out.println(usbinfo.getSerialno());
		System.out.println(usbinfo.getSignalg());
		System.out.println(usbinfo.getVersion());
		
		
		for(Provider p:Security.getProviders()){
			System.out.println(p);
			for(Map.Entry<Object, Object> entry:p.entrySet()){
				System.out.println("\t" + entry.getKey());
			}
		}
	}
}